package net.cmkj.mine.core.admin.sys.res;

import net.cmkj.mine.bean.SysRes;
import net.cmkj.mine.common.anno.RequiresPermissions;
import net.cmkj.mine.common.controller.BaseController;

public class ResController extends BaseController {
	
	private SysRes dao = SysRes.dao;
	
	@RequiresPermissions(value={"/sys/res"}) 
	public void index() {
		render("res.html");
	}
	
	@RequiresPermissions(value={"/sys/res"}) 
	public void form() throws Exception {
		Integer id=this.getParaToInt("id");
		Boolean isadd = this.getParaToBoolean("isadd");
		if(isadd != null && isadd){
			if(id != null){
				SysRes sysResTmp = new SysRes();
				sysResTmp.setPid(dao.findById(id).getId());
				setAttr("res",sysResTmp);
			}
		}else{
			if(id != null){
				SysRes sysRes = dao.findById(id);
				setAttr("res",sysRes);
			}
		}
		render("resForm.html");
	}
	
	/**
	 * 获取资源树列表
	 */
	@RequiresPermissions(value={"/sys/res"})
	public void  getTreeGridView() throws Exception {
		renderJson(dao.getTreeGridView());
	}
	
	/**
	 * 保存/修改资源信息
	 */
	@RequiresPermissions(value={"/sys/res"})
	public void save() throws Exception {
		Integer id=getParaToInt("id");
		String name=getPara("name");
		String seq=getPara("seq");
		String url=getPara("url");
		String iconcls=getPara("iconcls");
		String des=getPara("des");
		Integer type=getParaToInt("type");
		Integer pId=getParaToInt("pid");
		renderJson(dao.save(id, name, seq, url, iconcls, des, type, pId));
	}
	
	/**
	 * 设置数据启用/禁用
	 */
	@RequiresPermissions(value={"/sys/res"})
	public void visible() throws Exception {
		Integer visible=this.getParaToInt("visible");
		Integer id=this.getParaToInt("id");
		renderJson(dao.setVisible(id, visible));
	}

    @RequiresPermissions(value={"/sys/res"})
	public void getData() throws Exception {
		renderJson(dao.getData());
	}

	@RequiresPermissions(value={"/sys/res"})
	public void getChildren() throws Exception {
		Integer pid=getParaToInt("pid");
		renderJson(dao.getChildren(pid));
	}

}
